#include "reg52.h"
sbit K1 = P3^1;
sbit K2 = P3^0;
sbit K3 = P3^2;
sbit K4 = P3^3;
sbit LED1 = P2^0;
sbit LED2 = P2^1;
sbit LED3 = P2^2;
sbit LED4 = P2^3;

void delay(unsigned int x)
{
	while(x--);
}

int which_key_press()
{
	while(1)
	{
	delay(100);
	if(K1==0||K2==0||K3==0||K4==0)
	{
		delay(1000);
		if(K1==0) return 1;
		if(K2==0) return 2;
		if(K3==0) return 3;
		if(K4==0) return 4;
	}
	}	
}
void main()
{
	LED1 = 1;
	LED2 = 1;
	LED3 = 1;
	LED4 = 1;

	while(1)
	{
		int b = which_key_press();
		delay(10000);
		if(b==1)
		{
			LED1 =! LED1;	
		}
		if(b==2)
		{
			LED2 =! LED2;	
		}if(b==3)
		{
			LED3 =! LED3;	
		}if(b==4)
		{
			LED4 =! LED4;	
		}
	}
}